package org.lanqiao.webfm.model;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javacommon.ijdbc.RowMapper;

public class RightsUserMapper implements RowMapper<RightsUser>{
	private static final Logger LOGGER =LoggerFactory.getLogger(RightsUser.class);
	@Override
	public RightsUser mapRow(ResultSet rs) throws SQLException {
		RightsUser user = new RightsUser();
		user.setId(rs.getInt("id"));
		user.setUsername(rs.getString("username"));
		user.setPassword(rs.getString("password"));
		user.setName(rs.getString("name"));
		user.setPhonenumber(rs.getString("phonenumber"));
		user.setStatus(rs.getInt("status"));
		user.setRoleId(rs.getInt("role_id"));
		user.setIcon(rs.getString("icon"));
		user.setBirthday(rs.getDate("BIRTHDAY"));
		//有的使用到mapper的查询可能并未一并查询角色信息,所以此处是为了增强程序的健壮性
		try {
			RightsRole role = user.getRightsRole();
			role.setName(rs.getString("rolename"));
		} catch (Exception e) {
			LOGGER.warn("提取角色信息时出错,"+e.getMessage());
		}
		return user;
	}
	
}
